/** 
 * FunctionFrame.java
 * @author Lex
 * 2007-8-25 ����12:30:27
 */
package fun.ui.frames;

import java.awt.BorderLayout;

import fun.symtable.FunctionEntry;
import fun.ui.FunMainFrame;
import fun.ui.canvas.CanvasPane;
import fun.ui.canvas.DefaultCanvasModel;
import fun.ui.canvas.control.PopupMenu;

public class FunctionFrame extends BasicInternalFrame {
	private CanvasPane view = null;
	private int functionCount = 0;
	private StringBuilder title = new StringBuilder();

	public FunctionFrame(FunMainFrame mainframe) {
		super(mainframe);
		this.initialize();

	}

	public void addFunction(FunctionEntry function) {
		functionCount++;
		title.append(function.toString()).append(' ');
		if (functionCount < 2)
			this.setTitle(function.toFullString());
		else
			this.setTitle(title.toString());
		this.getView().addModel(new DefaultCanvasModel(function));
	}

	private void initialize() {
		this.setClosable(true);
		this.setLayout(new BorderLayout());
		this.add(this.getView(), BorderLayout.CENTER);
	}

	private CanvasPane getView() {
		if (null == view) {
			view = new CanvasPane();
			view.setInheritsPopupMenu(false);
			view.setComponentPopupMenu(new PopupMenu(mainframe, this, view));
		}
		return view;
	}
}
